import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class MemberLabelService extends BaseService<any> {
  private readonly logger = new Logger(MemberLabelService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getPage
   * 对应 PHP: MemberLabelService_admin::getPage()
   * 逻辑类型: undefined - undefined
   */
  async getPage(where: any[], order: any[]) {
    // 基于PHP真实逻辑: getPage
    // PHP原文: $field = 'label_id, site_id, label_name, memo, sort, create_time, update_time';         $search_model = $this->model->where([ [ 'site_id', '=', $this-...
const field = 'label_id, site_id, label_name, memo, sort, create_time, update_time';
        const search_model = this.model.where([ [ 'site_id', '=', this.site_id ) )).withSearch([ 'label_name' ), where).field(field).append([ "member_num" )).order(order];
        return this.pageQuery(search_model);
    }

    /**
     * 获取会员标签信息
     * @param int label_id
     * @return */
    async getInfo(int label_id)
    {
        const field = 'label_id, site_id, label_name, memo, sort, create_time, update_time';
        return this.model.field(field).where([ [ 'label_id', '=', label_id ], [ 'site_id', '=', this.site_id ) )).findOrEmpty().toArray(];
    }

    /**
     * 获取标签
     * @return * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getAll()
    {
        return ( this.coreMemberLabelService ).getAll(this.site_id);
    }

    /**
     * 添加会员标签
     * @param data
     * @return mixed
     */
    async add(data)
    {
        data[ 'site_id' ] = this.site_id;
        const res = this.model.create(data);
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return res.label_id;
    }

    /**
     * 会员标签编辑
     * @param int label_id
     * @param data
     * @return true
     */
    async edit(int label_id, data)
    {
        data[ 'update_time' ] = time(];
        this.model.where([ [ 'label_id', '=', label_id ], [ 'site_id', '=', this.site_id ) )).save(data);
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return true;
    }

    /**
     * 删除会员标签
     * @param int label_id
     * @return bool
     */
    async del(int label_id)
    {
        const res = this.model.where([ [ 'label_id', '=', label_id ], [ 'site_id', '=', this.site_id ) )).delete(];
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return res;
    }

    /**
     * 通过标签id获取标签列表
     * @param label_ids
     * @return Response
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getMemberLabelListByLabelIds(label_ids)
    {
        return ( this.coreMemberLabelService ).getMemberLabelListByLabelIds(this.site_id, label_ids);
    }

}
  }

  /**
   * getInfo
   * 对应 PHP: MemberLabelService_admin::getInfo()
   * 逻辑类型: undefined - undefined
   */
  async getInfo(label_id: number) {
    // 基于PHP真实逻辑: getInfo
    // PHP原文: $field = 'label_id, site_id, label_name, memo, sort, create_time, update_time';         return $this->model->field($field)->where([ [ 'label_id', '=',...
const field = 'label_id, site_id, label_name, memo, sort, create_time, update_time';
        return this.model.field(field).where([ [ 'label_id', '=', label_id ], [ 'site_id', '=', this.site_id ) )).findOrEmpty().toArray(];
    }

    /**
     * 获取标签
     * @return * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getAll()
    {
        return ( this.coreMemberLabelService ).getAll(this.site_id);
    }

    /**
     * 添加会员标签
     * @param data
     * @return mixed
     */
    async add(data)
    {
        data[ 'site_id' ] = this.site_id;
        const res = this.model.create(data);
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return res.label_id;
    }

    /**
     * 会员标签编辑
     * @param int label_id
     * @param data
     * @return true
     */
    async edit(int label_id, data)
    {
        data[ 'update_time' ] = time(];
        this.model.where([ [ 'label_id', '=', label_id ], [ 'site_id', '=', this.site_id ) )).save(data);
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return true;
    }

    /**
     * 删除会员标签
     * @param int label_id
     * @return bool
     */
    async del(int label_id)
    {
        const res = this.model.where([ [ 'label_id', '=', label_id ], [ 'site_id', '=', this.site_id ) )).delete(];
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return res;
    }

    /**
     * 通过标签id获取标签列表
     * @param label_ids
     * @return Response
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getMemberLabelListByLabelIds(label_ids)
    {
        return ( this.coreMemberLabelService ).getMemberLabelListByLabelIds(this.site_id, label_ids);
    }

}
  }

  /**
   * getAll
   * 对应 PHP: MemberLabelService_admin::getAll()
   * 逻辑类型: undefined - undefined
   */
  async getAll() {
    // 基于PHP真实逻辑: getAll
    // PHP原文: return ( new CoreMemberLabelService() )->getAll($this->site_id);     }      /**      * 添加会员标签      * @param array $data      * @return mixed      */  ...
return ( this.coreMemberLabelService ).getAll(this.site_id);
    }

    /**
     * 添加会员标签
     * @param data
     * @return mixed
     */
    async add(data)
    {
        data[ 'site_id' ] = this.site_id;
        const res = this.model.create(data);
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return res.label_id;
    }

    /**
     * 会员标签编辑
     * @param int label_id
     * @param data
     * @return true
     */
    async edit(int label_id, data)
    {
        data[ 'update_time' ] = time(];
        this.model.where([ [ 'label_id', '=', label_id ], [ 'site_id', '=', this.site_id ) )).save(data);
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return true;
    }

    /**
     * 删除会员标签
     * @param int label_id
     * @return bool
     */
    async del(int label_id)
    {
        const res = this.model.where([ [ 'label_id', '=', label_id ], [ 'site_id', '=', this.site_id ) )).delete(];
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return res;
    }

    /**
     * 通过标签id获取标签列表
     * @param label_ids
     * @return Response
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getMemberLabelListByLabelIds(label_ids)
    {
        return ( this.coreMemberLabelService ).getMemberLabelListByLabelIds(this.site_id, label_ids);
    }

}
  }

  /**
   * add
   * 对应 PHP: MemberLabelService_admin::add()
   * 逻辑类型: undefined - undefined
   */
  async add(data: any[]) {
    // 基于PHP真实逻辑: add
    // PHP原文: $data[ 'site_id' ] = $this->site_id;         $res = $this->model->create($data);         ( new CoreMemberLabelService() )->clearCache($this->site_id);...
data[ 'site_id' ] = this.site_id;
        const res = this.model.create(data);
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return res.label_id;
    }

    /**
     * 会员标签编辑
     * @param int label_id
     * @param data
     * @return true
     */
    async edit(int label_id, data)
    {
        data[ 'update_time' ] = time(];
        this.model.where([ [ 'label_id', '=', label_id ], [ 'site_id', '=', this.site_id ) )).save(data);
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return true;
    }

    /**
     * 删除会员标签
     * @param int label_id
     * @return bool
     */
    async del(int label_id)
    {
        const res = this.model.where([ [ 'label_id', '=', label_id ], [ 'site_id', '=', this.site_id ) )).delete(];
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return res;
    }

    /**
     * 通过标签id获取标签列表
     * @param label_ids
     * @return Response
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getMemberLabelListByLabelIds(label_ids)
    {
        return ( this.coreMemberLabelService ).getMemberLabelListByLabelIds(this.site_id, label_ids);
    }

}
  }

  /**
   * edit
   * 对应 PHP: MemberLabelService_admin::edit()
   * 逻辑类型: undefined - undefined
   */
  async edit(label_id: any[], data: any[]) {
    // 基于PHP真实逻辑: edit
    // PHP原文: $data[ 'update_time' ] = time();         $this->model->where([ [ 'label_id', '=', $label_id ], [ 'site_id', '=', $this->site_id ] ])->save($data);    ...
data[ 'update_time' ] = time(];
        this.model.where([ [ 'label_id', '=', label_id ], [ 'site_id', '=', this.site_id ) )).save(data);
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return true;
    }

    /**
     * 删除会员标签
     * @param int label_id
     * @return bool
     */
    async del(int label_id)
    {
        const res = this.model.where([ [ 'label_id', '=', label_id ], [ 'site_id', '=', this.site_id ) )).delete(];
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return res;
    }

    /**
     * 通过标签id获取标签列表
     * @param label_ids
     * @return Response
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getMemberLabelListByLabelIds(label_ids)
    {
        return ( this.coreMemberLabelService ).getMemberLabelListByLabelIds(this.site_id, label_ids);
    }

}
  }

  /**
   * del
   * 对应 PHP: MemberLabelService_admin::del()
   * 逻辑类型: undefined - undefined
   */
  async del(label_id: number) {
    // 基于PHP真实逻辑: del
    // PHP原文: $res = $this->model->where([ [ 'label_id', '=', $label_id ], [ 'site_id', '=', $this->site_id ] ])->delete();         ( new CoreMemberLabelService() )...
const res = this.model.where([ [ 'label_id', '=', label_id ], [ 'site_id', '=', this.site_id ) )).delete(];
        ( this.coreMemberLabelService ).clearCache(this.site_id);
        return res;
    }

    /**
     * 通过标签id获取标签列表
     * @param label_ids
     * @return Response
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getMemberLabelListByLabelIds(label_ids)
    {
        return ( this.coreMemberLabelService ).getMemberLabelListByLabelIds(this.site_id, label_ids);
    }

}
  }

  /**
   * getMemberLabelListByLabelIds
   * 对应 PHP: MemberLabelService_admin::getMemberLabelListByLabelIds()
   * 逻辑类型: undefined - undefined
   */
  async getMemberLabelListByLabelIds(label_ids: any[]) {
    // 基于PHP真实逻辑: getMemberLabelListByLabelIds
    // PHP原文: return ( new CoreMemberLabelService() )->getMemberLabelListByLabelIds($this->site_id, $label_ids);     }  }...
return ( this.coreMemberLabelService ).getMemberLabelListByLabelIds(this.site_id, label_ids);
    }

}
  }
}
